package com.smartsaas.ugclivii.cd;

import com.smartsaas.ugclivii.job.JobUtils;
import com.smartsaas.ugclivii.ui.UiContext;
import nxopen.*;
import nxopen.blockstyler.Node;
import nxopen.blockstyler.Tree;
import org.apache.commons.lang3.StringUtils;

import java.rmi.RemoteException;
import java.util.List;

public class DesignTreeSelectHandler  implements Tree.OnSelectCallback{
    @Override
    public void onSelectCallback(Tree tree, Node node, int i, boolean b) throws NXException, RemoteException {
        String layerString = node.getColumnDisplayText(0);
        if (StringUtils.isNotBlank(layerString)) {
            selectBody(layerString);
        }
    }

    public static void selectBody(String layerString) throws RemoteException, NXException {
        int layer = Integer.parseInt(layerString);
        BodyCollection bodies = UiContext.SESSION.parts().work().bodies();
        TaggedObjectCollection.Iterator iterator = bodies.iterator();
        while (iterator.hasNext()){
            Body next = (Body) iterator.next();
            if (next.layer() == layer) {
                next.unblank();
            }else {
                next.blank();
            }
        }
    }
}
